home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor1 / pyth.doc < prev    next >
Text File  |  1995-03-31  |  2KB  |  40 lines

  1. Author: Joe Horn 
  2.  
  3. PYTH: A Primitive Pythagorean Triangle generator. 
  4.  
  5. Place two integers on the stack and run PYTH.  A list { A B C } will 
  6. be returned containing the lengths of the sides of a right triangle. 
  7.  
  8. A right triangle is considered "Pythagorean" if the lengths of all 
  9. three sides are integers.  (The 3-4-5 and 5-12-13 right triangles 
  10. are the smallest, and are familiar to all math students.  There are 
  11. infinitely many more.)  PYTH will always return a Pythagorean 
  12. triangle. 
  13.  
  14. A Pythagorean triangle is considered "primitive" if the lengths of 
  15. all three sides are relatively prime (that is, there are no factors 
  16. shared between any two of them).  For example, the 104-153-185 right 
  17. triangle is primitive because 104, 153 and 185 share no common 
  18. factors.  PYTH will return a primitive Pythagorean triangle if (a) 
  19. the two numbers you give it are (a) relatively prime, and (b) one of 
  20. them is even.  For example, 77 and 52 (relatively prime, and 52 is 
  21. even) yield the 3225-8008-8633 primitive Pythagorean triangle. 
  22.  
  23. To check relative primality, run GCD (Greatest Common Divisor); if it 
  24. is 1, then the two numbers were relatively prime. 
  25.  
  26. While I was at it, I threw in LCM (Least Common Multiple) and RDC 
  27. (Reduce).  RDC removes the common factors from two integers, thus 
  28. reducing them to two relatively prime numbers. 
  29.  
  30. If X and Y are the inputs, and { A B C } is the output of PYTH, 
  31. the formulas that relate them are: 
  32.  
  33.    A = ABS( X^2 - Y^2 ) 
  34.    B = 2 * X * Y 
  35.    C = X^2 + Y^2 
  36.  
  37. Notice that these equations are nowhere in the program... 
  38.  
  39.   -jkh- 
  40.